package com.liandu.common.utils;

import com.liandu.common.PageInfo;
import com.liandu.common.parent.BaseEntity;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

public class EntityUtil {

    //获取分页对象
    public static Pageable getPageable(BaseEntity baseEntity, Sort sort){
        PageInfo pageInfo = baseEntity.getPage();
        sort = sort == null ? Sort.unsorted() : sort;
        if (pageInfo == null || pageInfo.getPageNum() == null || pageInfo.getPageSize() == null){
            return PageRequest.of(0,10,sort);
        }
        return PageRequest.of(pageInfo.getPageNum()-1,pageInfo.getPageSize(),sort);
    }
}
